#ifndef __DATABASE_USER_SQL_RUN_EVENT_HPP__
#define __DATABASE_USER_SQL_RUN_EVENT_HPP__


#ifdef ENABLE_DB_JUDGE

#include "base_event.hpp"

namespace run_code_event_space {

struct database_user_sql_run_event : base_event<database_user_sql_run_event> {
    template <class U>
    ProcessStatus execute_impl(run_code_context_t<U>& context, const string& inFile);
};

template <class U>
ProcessStatus database_user_sql_run_event::execute_impl(run_code_context_t<U>& context, const string& inFile) {
    if constexpr (contains_v<U, DatabaseModifyJudge, DatabaseSelectJudge>) {
        const U& judge_type = context.judge_type;
        const RuncodeParams& params = context. params;
        int mode = std::is_same_v<U, DatabaseSelectJudge> ? DATABASE_SELECT_JUDGE : DATABASE_MODIFY_JUDGE;

        return general_execution_strategy::run_sql<true>(&context.judge_type.conn, context.judge_type.database_name, judge_type.userFile, mode, inFile, "", params.timeLimit, params.memoryLimit);
    }
    return ProcessStatus{ .result = RUN_FAIL, .error = "no support"};
}

}

#endif

#endif /* __DATABASE_USER_SQL_RUN_EVENT_HPP__ */
